#include "PointsLightsManager.h"
#include "BasicEffect.h"

PointsLightsManager::PointsLightsManager()
{

}

PointsLightsManager::PointsLightsManager(const PointsLightsManager&)
{

}

PointsLightsManager::~PointsLightsManager()
{

}

void PointsLightsManager::SetBasicEffect(BasicEffect* pBasicEffect)
{
	mBasicEffect = pBasicEffect;
}

bool PointsLightsManager::Initialize()
{
	return true;
}

void PointsLightsManager::Uninit()
{

}

void PointsLightsManager::Update()
{
	if(mChangeSinceLastUpdate)
	{
		int pointLightNum = 0;
		for(std::map<int, PointLight*>::iterator pointLightIt = mHashPointLight.begin();pointLightIt != mHashPointLight.end();++pointLightIt)
		{
			mListPointsLights[pointLightNum] = (*pointLightIt->second);
			pointLightNum++;
		}
		mBasicEffect->SetPointLightList(mListPointsLights, pointLightNum);
	}
	mChangeSinceLastUpdate = false;
}

void PointsLightsManager::AddLight(PointLight *pLight)
{
	int ptr = (int)pLight;
	mHashPointLight[ptr] = pLight;
	mChangeSinceLastUpdate = true;
}

void PointsLightsManager::RemoveLight(PointLight *pLight)
{
	mHashPointLight.erase((int)pLight);
	mChangeSinceLastUpdate = true;
}